package com.ly.hotel.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Vector;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;

import androidx.multidex.MultiDexApplication;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ly.hotel.R;
import com.ly.hotel.model.Ad;
import com.ly.hotel.model.AppInfo;
import com.ly.hotel.model.BackgroundInfo;
import com.ly.hotel.model.ChatQrCodeInfo;
import com.ly.hotel.model.Device;
import com.ly.hotel.model.DeviceInfo;
import com.ly.hotel.model.Episodepart;
import com.ly.hotel.model.IconAnimationDetail;
import com.ly.hotel.model.LiveManagement;
import com.ly.hotel.model.ModelBean;
import com.ly.hotel.model.ScrollMessage;
import com.ly.hotel.model.SeatPicInfo;
import com.ly.hotel.model.StartUpGuideInfo;
import com.ly.hotel.model.TimingMsgBean;
import com.ly.hotel.model.VodVideoBean;
import com.ly.hotel.model.Vodvideo;
import com.ly.hotel.model.Weather;
import com.ly.hotel.model.WeatherMsg;
import com.ly.hotel.model.Websites;
import com.ly.hotel.model.YouhuiMessage;
import com.ly.hotel.model.MusicAlbumBean;
import com.ly.hotel.model.MusicBean;
import com.ly.hotel.model.MusicPageBean;
import com.ly.hotel.model.Serve;
import com.ly.hotel.model.ServerMsg;
import com.ly.hotel.model.Soft;
import com.ly.hotel.model.Vodpart;
import com.ly.hotel.model.WeatherInfor;
import com.ly.hotel.msgevent.SyncCallEvent;
import com.ly.hotel.msgevent.UpdateBottomStateEvent;
import com.ly.hotel.service.SPAService;
import com.ly.hotel.spainterface.jxd.bean.JxdXfTypeBean;
import com.ly.hotel.spainterface.nm.bean.NmXFBuyItemBean;
import com.ly.hotel.spainterface.nm.bean.NmXFTypeBean;
import com.ly.hotel.spainterface.nm.bean.XFBillBean;
import com.ly.hotel.util.AppUtil;
import com.ly.hotel.util.HardInfoUtil;
import com.ly.hotel.adaptor.NetworkUtil;
import com.ly.hotel.adaptor.HardwareInterface;
import com.ly.hotel.view.common.BottomItemInfo;
import com.ly.hotel.view.common.HotelMassage;
import com.ly.hotel.view.fragments.query.AreaMsgBean;

import de.greenrobot.event.EventBus;

public class MyApplication extends MultiDexApplication {
	public static final int DETAULT_THEME = R.style.mainStyle1;

	private static String mac;

	private static String hostResUrl;//其实就是upload文件夹
	public static String hostMyResUrl;//用来存放服务器协助下载的资源(广告文件，升级用的apk等)
	
	// 默认主题
	private int mainTheme = DETAULT_THEME;
	private boolean start = false;
	public static boolean cloudStart = false;
	private volatile static boolean logined = false;
	// 天气预报
	private WeatherInfor weatherInfo = new WeatherInfor();
	private static Device deviceInfo = null; // -- chen -- 我设为了static
	public static DeviceInfo fullDeviceInfo = null;
	// 音乐欣赏树状结构(MusicArea->AlbumPages->Albums->MusicPages->Musics)
	private List<MusicAlbumBean> musicRepos = new Vector<>();// 所有音乐专辑
	// 优惠消息
	private List<YouhuiMessage> messages = new Vector<>();

	// 滚动消息
	private List<ScrollMessage> scrollMsg = new Vector<>();
	// 定时消息
	public static List<TimingMsgBean> timingMsg = new Vector<>();
	// 点播
	private static List<Vodpart> vodpart = new Vector<>();

	//主页图标
	private static List<IconAnimationDetail> iconList = new Vector<>();

	//播放历史
	public List<Vodvideo> vodHistory = new ArrayList<>();
	//电视剧类型列表
	public static List<Episodepart> vodEpisode = new ArrayList<>();
	//所有片源的列表
	public List<Vodvideo> vods = new ArrayList<>();

	public List<NmXFBuyItemBean> shopCartList = new ArrayList<>();

	public List<NmXFTypeBean> nmXFTypeList = new ArrayList<>();

	public List<JxdXfTypeBean> jxdXfTypeBeanList = new ArrayList<>();

	public List<XFBillBean> xfBillBeanList = new ArrayList<>();

	public List<Weather> weathers = new ArrayList<>();

	public List<AreaMsgBean> areaMsgBeanList = new ArrayList<>();

	public WeatherMsg nowWeather = null;
	public String areaId;
	public String areaName;

	//需要播放的片源的列表
	public List<Vodvideo> vodsList = new ArrayList<>();

	public String wifiName;

	public String wifiPwd;

	//电影搜索的结果
	public VodVideoBean vodSearchVideos = new VodVideoBean();
	// 直播数据
	private List<LiveManagement> liveList;

	// 点播名字列表
	private List<String> vodListName = new Vector<>();

	// 应用
	private List<AppInfo> appInfo = new Vector<>();
	//第三方APP
	private List<AppInfo> thirdApp = new Vector<>();
	// 浏览器
	private List<AppInfo> interInfo = new Vector<>();
	// 更新
	private Soft soft;
	// 背景信息
	private BackgroundInfo bgInfo;

	private SeatPicInfo seatPicInfo;
	private StartUpGuideInfo StartUpGuideInfo;
	// 本店介绍
	private List<Serve> shopIntroduce = new Vector<>();
	// 本店介绍
	private List<Websites> websites = new Vector<>();
	// 消息通知
	private List<ServerMsg> serverMsgList;

	private static String expWebUrl="";
	public static String pluginCfg="";
	private static Bitmap bgBitmap = null;
	private static Bitmap logoBitmap = null;
	private static Bitmap seatBitmap = null;

	//时间
	public String nowTime = "2018-01-08 18:08:08";


	private static List<BottomItemInfo> btnItemInfo = new Vector<>();
	private static List<WeatherMsg> weatherMsgs = new ArrayList<>();
	private Ad ad;

	private int callStatus = Constants.CALL_CANCLE;

	private String myIpAddr = "";

	private int liuweiTime = 15;

	private static int serialBaud = 9600;

	public static boolean isLoopPlay = false;
	public static boolean isSelectLang = false;
	public boolean appShowTpis = true;//应用页面提示账号安全信息
	public boolean gameShowTpis = true;//游戏页面提示账号安全信息
	private ArrayList<HotelMassage> rtMsgList = new ArrayList<>();

	private static String apkVersion = null;
	public static String systemVersion = null;
	public static String serverApiVersion = null;//服务器接口版本
	public static String serverVersion = null;//服务器接口版本
	/* 给Lyagent使用的存储空间 */
	private HashMap<String, String> mySpaceMap = new HashMap<>();

	public static List<MusicBean> musicPlayList = new ArrayList<>();

	public static String lastCallStatus = "";// 保存上一次的呼叫状态“请求”，“处理完成”，“取消请求”等
	public static String authToCompany = "未获得授权";
	public boolean enableServerLed = true;
	
	public static String HOST_URL = "http://" + Constants.DEFAULT_SPA_SERVER + "/";
	public static String HOST_IP = Constants.DEFAULT_SPA_SERVER;
	
	public boolean serviceInit = false;
	public boolean syatemCompleteStart = false;
	public static boolean serverAssess = false;
	public static boolean licenseTimeOut = false;

	/** OPlayer SD卡缓存路径 */
	public static final String OPLAYER_CACHE_BASE = Environment.getExternalStorageDirectory() + "/oplayer";
	/** 视频截图缓冲路径 */
	public static final String OPLAYER_VIDEO_THUMB = OPLAYER_CACHE_BASE + "/thumb/";
	/** 首次扫描 */
	public static final String PREF_KEY_FIRST = "application_first";

	private static MyApplication mApplication;
	
	public static boolean ada628Player = true;
	
	public static String clouldCtlUrl="";
	public static ChatQrCodeInfo chatQrCodeInfo=null;
	public static boolean canRunRootCommands = false;
	public static boolean haveCardReader = false;
	public static String shareUid = "";
	
	public static int screenHeight = 720;
	public static int screenWidth = 1280;
	
	public static String interfaceServerIp = "";
	public static String interfaceServerPort = "";
	public static String interfaceVersion = "";
	public static String myRoomNo = "";
	
	public int brivalue = 6;
	public static boolean localUpdatting = false;
	public static Locale currectLocale = Locale.SIMPLIFIED_CHINESE;
	public static String spaVersion = "";
	public static String startUpTime = "";				//开机时得服务器时间
	public static String ukeyInvalidTime = "";			//开机时得服务器时间,不包括时分秒
	public static long ukeyInvalidDays = 0;  			//过期的天数
	public static int startUpTimeHour = 0;				//开机时服务器是几点
	
	public static boolean chatQrCodeDisturb  = false;	//是否禁止技师聊天请求
	public static int softBlacklightValue = 1;
	
	public static boolean isInternetAvailable = false;
	public static boolean isSupportRemote = false;		//是否对遥控器操作进行优化
	
	public static String pingMs = "获取不到";

	public boolean isAgreeVod = false;
	public boolean isAgreeEpisode = false;
	public boolean isAgreeMuc = false;

	public String homeSort;
	@Override
	public void onCreate() {
		super.onCreate();
		mApplication = this;
		//canRunRootCommands = RunCmdAsRoot.canRunRootCommands();
		if(Build.BOARD.endsWith(Constants.BOARD_TYPE_ADA801_NAME)){
			canRunRootCommands  = true;
			haveCardReader = true;
		} else if(Build.BOARD.endsWith(Constants.BOARD_TYPE_ADA628_NAME)){
			if(AppUtil.getVersionName(this, getPackageName()).startsWith("3.")){
				canRunRootCommands  = false;
				haveCardReader = false;
			} else {
				canRunRootCommands  = true;
				haveCardReader = true;
			}
		} else if(Build.BOARD.endsWith(Constants.BOARD_TYPE_ADA648_NAME) || Build.BOARD.endsWith(Constants.BOARD_TYPE_6A648_NAME)) {
			canRunRootCommands  = false;
			haveCardReader = true;
		}else{
				canRunRootCommands  = false;
				haveCardReader = false;
		}
		try {
			PackageInfo p = getPackageManager().getPackageInfo("com.ly.hotel", 0);
			shareUid = p.sharedUserId;
			Log.i("init", "UID = " + shareUid + ",是否支持静默安装:" + canRunRootCommands); 
			
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		initApkVersion();
	}

	public static Context getContext() {
		return mApplication;
	}

	public static MyApplication getInstance() {
		return mApplication;
	}
	/**
	 * 设置ip,端口 格式 192.168.1.110:9999
	 * 
	 * @param host
	 */
	public static void setHost(String host) {
		if (host == null) {
			return;
		}
		HOST_IP = host;
		HOST_URL = "http://" + host + "/";
	}

	public static String getHost() {
		return HOST_URL;
	}

	public static String getHostIp() {
		return HOST_IP;
	}


	private void initApkVersion() {
		PackageManager pm = this.getPackageManager();
		int flags = PackageManager.GET_UNINSTALLED_PACKAGES;
		PackageInfo pkgInfo = null;
		try {
			pkgInfo = pm.getPackageInfo("com.ly.hotel", flags);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
		// 获取APK的版本
		apkVersion = pkgInfo.versionName + "." + pkgInfo.versionCode;

	}

	
	//系统权限，通过Ukey初始化的
	public static HashMap<String, Integer> mylicense = new HashMap<String, Integer>();
	
	public static void myLicensePutValue(String key, Integer value) {
		if (mylicense != null) {
			if(mylicense.containsKey(key)){
				mylicense.remove(key);
			}
			mylicense.put(key, value);
		}
	}

	public static Integer myLicenseGetValue(String key) {
		if (mylicense != null) {
			if(mylicense.containsKey(key)){
				return mylicense.get(key);
			}else{
				return 0;
			}
		} else {
			return 0;
		}
	}
	
	public List<AppInfo> getThirdApps() {
		return thirdApp;
	}

	public void setThirdApps(List<AppInfo> thirdApp) {
		this.thirdApp = thirdApp;
	}

	
	public String getAuthToCompany() {
		return authToCompany;
	}

	public static void setAuthToCompany(String auth) {
		authToCompany = auth;
	}

	public void mySpacePutValue(String key, String value) {
		if (mySpaceMap != null) {
			mySpaceMap.put(key, value);
		}
	}

	public String mySpaceGetValue(String key) {
		if (mySpaceMap != null) {
			return mySpaceMap.get(key);
		} else {
			return "";
		}
	}

	public String mySpaceDelKey(String key) {
		if (mySpaceMap != null) {
			return mySpaceMap.remove(key);
		} else {
			return "";
		}
	}

	public String mySpaceIsKey(String key) {
		if (mySpaceMap != null && mySpaceMap.containsKey(key)) {
			return "true";
		} else {
			return "false";
		}
	}

	public String mySpaceGenKeys() {
		if (mySpaceMap != null && mySpaceMap.size() != 0) {
			String result = "";
			for (String i : mySpaceMap.keySet()) {
				result += i + "-"; // 所以key中不能具有","与"-"
			}
			return result.substring(0, result.length() - 1);
		} else {
			return "";
		}
	}

	public void mySpaceEmpty() {
		mySpaceMap.clear();
	}

	public ArrayList<HotelMassage> getRtMsgList() {
		return rtMsgList;
	}

	public void setRtMsg(String msg) {
		if(msg.startsWith("WINDOW:")){
			msg = msg.replaceFirst("WINDOW:", "");
		}
		if(msg.startsWith("\n")){
			msg = msg.replaceFirst("\n", "");
		}
		HotelMassage hotelMassage = new HotelMassage(msg,nowTime,false);
		rtMsgList.add(0,hotelMassage);
	}

	public void removeRtMsg(int index) {
		if (this.rtMsgList.size() > index) {
			this.rtMsgList.remove(index);
		}
	}

	public static int getSerialBaud() {
		return serialBaud;
	}

	public void setSerialBaud(int serialBaud) {
		this.serialBaud = serialBaud;
	}

	public int getLiuweiTime() {
		return liuweiTime;
	}

	public void setLiuweiTime(int liuweiTime) {
		this.liuweiTime = liuweiTime;
	}

	public String getMyIpAddr() {
		return myIpAddr;
	}

	public void setMyIpAddr(String myIpAddr) {
		this.myIpAddr = myIpAddr;
	}

	public int getCallStatus() {
		return callStatus;
	}

	public void setCallStatus(int callStatus) {
		this.callStatus = callStatus;
	}

	// 当前再最顶层的activity
	public String getTopActivity() {
		ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
		List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);

		/*当有两个launch的时候，此处以null来判断会报错
		java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
		因为list集合本身是不会为null的*/
		if (runningTaskInfos != null && runningTaskInfos.size() != 0 ) {
			return (runningTaskInfos.get(0).topActivity).toString();
		} else {
			return null;
		}
	}

	public static Bitmap getBgBitmap() {
		return bgBitmap;
	}

	public static void setBgBitmap(Bitmap bgBitmap) {
		MyApplication.bgBitmap = bgBitmap;
	}

	public static Bitmap getLogoBitmap() {
		return logoBitmap;
	}

	public static void setLogoBitmap(Bitmap logoBitmap) {
		MyApplication.logoBitmap = logoBitmap;
	}

	public static Bitmap getSeatBitmap() {
		return seatBitmap;
	}

	public static void setSeatBitmap(Bitmap seatBitmap) {
		MyApplication.seatBitmap = seatBitmap;
	}
	

	public static String getExpWebUrl() {
		return expWebUrl;
	}

	public static void setExpWebUrl(String expWebUrl) {
		MyApplication.expWebUrl = expWebUrl;
	}

	public void initBtnItemInfo() {
		if (btnItemInfo.size() == 0) {
			// 初始化底部导航栏的信息
			//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!这里的中文描述要和U盾的一样！！！！！！！！！！！！！！！！！！！！！！！！！1
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviIntroName),"介绍", true, MyKeyEventCode.KEYCODE_INTRO, R.drawable.btn_h_intro));
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviMovieName),"电影", true, MyKeyEventCode.KEYCODE_MOVICE, R.drawable.btn_h_movie));
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviTvName),"电视", true, MyKeyEventCode.KEYCODE_TV, R.drawable.btn_h_tv));
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviXiaofeiName),"消费", false, MyKeyEventCode.KEYCODE_XIAOFEI, R.drawable.btn_h_shop));
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviTechnicianName),"技师", false, MyKeyEventCode.KEYCODE_JISHI, R.drawable.btn_h_technician));
			//当没有对接客控系统时，后台不配置即可
			if (!TextUtils.isEmpty(SysConf.extendConfGetValue(SysConf.SYS_CONF_GUESTCONTORL_PACKET_NAME, ""))){
				btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviContorlName),"客控",true,MyKeyEventCode.KEYCODE_CONTORL,R.drawable.btn_h_guest_control));
			}
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviQueryName),"查询", true, MyKeyEventCode.KEYCODE_YOUHUI, R.drawable.btn_h_search));
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviMsgName),"消息", true, MyKeyEventCode.KEYCODE_MASSAGE, R.drawable.btn_h_massage));
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviAppName),"应用", false, MyKeyEventCode.KEYCODE_INTERNET, R.drawable.btn_h_app));
			btnItemInfo.add(new BottomItemInfo(this.getString(R.string.naviLangName),"语言",true,MyKeyEventCode.KEYCODE_ABOUT, R.drawable.btn_h_lang));

		}
	}

	public void initWeatherMsgs() {
		if(weatherMsgs.size() == 0){
			weatherMsgs.add(new WeatherMsg("0","晴","Sunny",R.drawable.w_0));
			weatherMsgs.add(new WeatherMsg("1","晴","Clear",R.drawable.w_1));
			weatherMsgs.add(new WeatherMsg("2","晴","Fair",R.drawable.w_2));
			weatherMsgs.add(new WeatherMsg("3","晴","Fair",R.drawable.w_3));
			weatherMsgs.add(new WeatherMsg("4","多云","Cloudy",R.drawable.w_4));
			weatherMsgs.add(new WeatherMsg("5","晴间多云","Partly Cloudy",R.drawable.w_5));
			weatherMsgs.add(new WeatherMsg("6","晴间多云","Partly Cloudy",R.drawable.w_6));
			weatherMsgs.add(new WeatherMsg("7","大部多云","Mostly Cloudy",R.drawable.w_7));
			weatherMsgs.add(new WeatherMsg("8","大部多云","Mostly Cloudy",R.drawable.w_8));
			weatherMsgs.add(new WeatherMsg("9","阴","Overcast",R.drawable.w_9));
			weatherMsgs.add(new WeatherMsg("10","阵雨","Shower",R.drawable.w_10));
			weatherMsgs.add(new WeatherMsg("11","雷阵雨","Thundershower",R.drawable.w_11));
			weatherMsgs.add(new WeatherMsg("12","雷阵雨伴有冰雹","Thundershower with Hail",R.drawable.w_12));
			weatherMsgs.add(new WeatherMsg("13","小雨","Light Rain",R.drawable.w_13));
			weatherMsgs.add(new WeatherMsg("14","中雨","Moderate Rain",R.drawable.w_14));
			weatherMsgs.add(new WeatherMsg("15","大雨","Heavy Rain",R.drawable.w_15));
			weatherMsgs.add(new WeatherMsg("16","暴雨","Storm",R.drawable.w_16));
			weatherMsgs.add(new WeatherMsg("17","大暴雨","Heavy Storm",R.drawable.w_17));
			weatherMsgs.add(new WeatherMsg("18","特大暴雨","Severe Storm",R.drawable.w_18));
			weatherMsgs.add(new WeatherMsg("19","冰雨","Ice Rain",R.drawable.w_19));
			weatherMsgs.add(new WeatherMsg("20","雨夹雪","Sleet",R.drawable.w_20));
			weatherMsgs.add(new WeatherMsg("21","阵雪","Snow Flurry",R.drawable.w_21));
			weatherMsgs.add(new WeatherMsg("22","小雪","Light Snow",R.drawable.w_22));
			weatherMsgs.add(new WeatherMsg("23","中雪","Moderate Snow",R.drawable.w_23));
			weatherMsgs.add(new WeatherMsg("24","大雪","Heavy Snow",R.drawable.w_24));
			weatherMsgs.add(new WeatherMsg("25","暴雪","Snowstorm",R.drawable.w_25));
			weatherMsgs.add(new WeatherMsg("26","浮尘","Dust",R.drawable.w_26));
			weatherMsgs.add(new WeatherMsg("27","扬沙","Sand",R.drawable.w_27));
			weatherMsgs.add(new WeatherMsg("28","沙尘暴","Duststorm",R.drawable.w_28));
			weatherMsgs.add(new WeatherMsg("29","强沙尘暴","Sandstorm",R.drawable.w_29));
			weatherMsgs.add(new WeatherMsg("30","雾","Foggy",R.drawable.w_30));
			weatherMsgs.add(new WeatherMsg("31","霾","Haze",R.drawable.w_31));
			weatherMsgs.add(new WeatherMsg("32","风","Windy",R.drawable.w_32));
			weatherMsgs.add(new WeatherMsg("33","大风","Blustery",R.drawable.w_33));
			weatherMsgs.add(new WeatherMsg("34","飓风","Hurricane",R.drawable.w_34));
			weatherMsgs.add(new WeatherMsg("35","热带风暴","Tropical Storm",R.drawable.w_35));
			weatherMsgs.add(new WeatherMsg("36","龙卷风","Tornado",R.drawable.w_36));
			weatherMsgs.add(new WeatherMsg("37","冷","Cold",R.drawable.w_37));
			weatherMsgs.add(new WeatherMsg("38","热","Hot",R.drawable.w_38));
			weatherMsgs.add(new WeatherMsg("99","未知","Unknown",R.drawable.w_99));
		}
	}

	//通过天气代码获取当前所属天气信息
	public WeatherMsg getWeatherName(String code){
		WeatherMsg wm = null;
		for (WeatherMsg w : weatherMsgs) {
			if (w.getCode().equals(code)) {
				wm = w;
				break;
			}
		}
		return wm;
	}

	public boolean setBtnItemInfo(String name, boolean state) {

		if (name != null) {
			for (BottomItemInfo b : btnItemInfo) {
				if (b.getName().equals(name)) {
					b.setEnable(state);
					return true;
				}
			}
		}
		return false;
	}

	public boolean isBtnItemEnable(String name) {

		if (name != null) {
			for (BottomItemInfo b : btnItemInfo) {
				if (b.getName().equals(name)) {
					return b.isEnable();
				}
			}
		}
		return false;
	}
	
	public int getBtnItemKeyCode(String name) {

		if (name != null) {
			for (BottomItemInfo b : btnItemInfo) {
				if (b.getName().equals(name)) {
					return b.getKeyCode();
				}
			}
		}

		return 0;
	}

	public boolean getBtnItemRespond(String name) {

		if (name != null) {
			for (BottomItemInfo b : btnItemInfo) {
				if (b.getName().equals(name)) {
					return b.isRespond();
				}
			}
		}
		return false;
	}

	public boolean setBtnItemRespond(String name, boolean state) {

		if (name != null) {
			for (BottomItemInfo b : btnItemInfo) {
				if (b.getName().equals(name)) {
					b.setRespond(state);
					return true;
				}
			}
		}
		return false;
	}

	// btnItemInfo要是静态的，都在返回数据会是空的
	public List<BottomItemInfo> getBtnItemInfo() {
		return btnItemInfo;
	}

	// 手牌号
	private static String bandNo = "";
	public static boolean adEnable = false; //U盾控制的广告开关

	public static boolean interfaceEnable = true;
	
	public static String getBandNo() {
		return bandNo;
	}

	public static boolean isNumeric(String str) {
		for (int i = 0; i < str.length(); i++) {
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	public static void setBandNo(String no) {

		for (int i = 0; i < no.length(); i++) { // 循环遍历字符串

			if (!isNumeric(no.valueOf(i))) { // 用char包装类中的判断数字的方法判断每一个字符
				bandNo = "";
				return;
			}
		}

		bandNo = no;
	}

	public static void clearBandNo() {
		bandNo = "";
	}

	public BackgroundInfo getBgInfo() {
		return bgInfo;
	}

	public void setBgInfo(BackgroundInfo bgInfo) {
		this.bgInfo = bgInfo;
	}

	public SeatPicInfo getSeatPicInfo() {
		return seatPicInfo;
	}

	public void setSeatPicInfo(SeatPicInfo seatPicInfo) {
		this.seatPicInfo = seatPicInfo;
	}

	public StartUpGuideInfo getStartUpGuideInfo() {
		return StartUpGuideInfo;
	}

	public void setStartUpGuideInfo(StartUpGuideInfo startUpHelpInfo) {
		StartUpGuideInfo = startUpHelpInfo;
	}

	public WeatherInfor getWeatherInfo() {
		return weatherInfo;
	}

	public void setWeatherInfo(WeatherInfor weatherInfo) {
		this.weatherInfo = weatherInfo;
	}

	public static boolean isLogined() {
		return logined;
	}

	public void setLogined(boolean logined) {
		this.logined = logined;
	}

	public static Device getDeviceInfo() {
		return deviceInfo;
	}

	public void setDeviceInfo(Device deviceInfo) {
		MyApplication.deviceInfo = deviceInfo;
	}

	public Ad getAd() {
		return ad;
	}

	public void setAd(Ad ad) {
		this.ad = ad;
	}

	public List<ServerMsg> getServerMsgList() {
		return serverMsgList;
	}

	public void setServerMsgList(List<ServerMsg> serverMsgList) {
		this.serverMsgList = serverMsgList;
	}

	public List<Serve> getShopIntroduce() {
		return shopIntroduce;
	}

	public void setShopIntroduce(List<Serve> shopIntroduce) {
		this.shopIntroduce = shopIntroduce;
	}

	public List<Websites> getWebsites() {
		return websites;
	}

	public void setWebsites(List<Websites> websites) {
		this.websites = websites;
	}

	public Soft getSoftUpdate() {
		return soft;
	}

	public void setSoftUpdate(Soft soft) {
		this.soft = soft;
	}

	public List<AppInfo> getInterInfo() {
		return interInfo;
	}

	public void setInterInfo(List<AppInfo> interInfo) {
		this.interInfo = interInfo;
	}

	public List<AppInfo> getAppInfo() {
		return appInfo;
	}

	public void setAppInfo(List<AppInfo> appInfo) {
		this.appInfo = appInfo;
	}

	public List<String> getVodListName() {
		return vodListName;
	}

	public void setVodListName(List<String> vodListName) {
		this.vodListName = vodListName;
	}

	public static List<Vodpart> getVodpart() {
		return vodpart;
	}

	public void setVodpart(List<Vodpart> vodpart) {
		this.vodpart = vodpart;
	}

	public void setHomeIcon(List<IconAnimationDetail> icons){
		this.iconList = icons;
	}

	public static List<IconAnimationDetail> getHomeIcon(){
		return iconList;
	}

	public static List<Episodepart> getVodEpisode() {
		return vodEpisode;
	}

	public void setVodEpisode(List<Episodepart> vodEpisode) {
		this.vodEpisode = vodEpisode;
	}


	public synchronized List<YouhuiMessage> getMessages() {
		return messages;
	}

	public synchronized void setMessages(List<YouhuiMessage> messages) {
		this.messages = messages;
	}

	public synchronized List<ScrollMessage> getScrollMsg() {
		return scrollMsg;
	}

	public synchronized void setScrollMsg(List<ScrollMessage> scrollMsg) {
		this.scrollMsg = scrollMsg;
	}

	// 设置所有专辑
	public void setMusicArea(List<MusicAlbumBean> musicArea) {
		this.musicRepos = musicArea;
	}

	// 获取区域的列表
	public synchronized List<MusicAlbumBean> getMusicRepos() {
		return musicRepos;
	}

	// 设置专辑歌曲
	public void setMusicPage(int albumId, MusicPageBean musics) {
		if (musicRepos != null) {
			for (MusicAlbumBean bb : musicRepos) {// 搜索专辑
				if (bb.getAlbumId() == albumId) {// 匹配ID
					bb.addMusicPages(musics);
					return;
				}
			}
		}
		Log.e("music","setMusicPage:fail");
	}

	// 获取专辑的所有音乐
	public List<MusicBean> getMusics(int albumId) {
		List<MusicBean> mb = new Vector<MusicBean>();

		if (musicRepos != null) {
			for (MusicAlbumBean bb : musicRepos) {// 搜索专辑
				if (bb.getAlbumId() == albumId) {// 匹配ID
					for (MusicPageBean bbb : bb.getMusicPages()) {// 获取音乐页面列表
						for (MusicBean bbbb : bbb.getMusics()) {// 获取音乐,所有音乐整合在一起
							mb.add(bbbb);
						}
					}
				}
			}
		}

		return mb;
	}

	// MAC 地址
	public static String getMAC() {
		if (mac == null || mac.trim().equals("")) {
			mac = HardInfoUtil.getMacAddress();
		}
		return mac;
	}

	public synchronized boolean isStart() {
		return start;
	}

	public synchronized void setStart(boolean start) {
		this.start = start;
	}

	public int getMainTheme() {
		return mainTheme;
	}

	public void setMainTheme(int mainTheme) {
		this.mainTheme = mainTheme;
	}

	public List<LiveManagement> getLiveList() {
		return liveList;
	}

	public void setLiveList(List<LiveManagement> liveList) {
		this.liveList = liveList;
	}

	public static String getHostResUrl() {
		return hostResUrl;
	}

	public static void setHostResUrl(String hostResUrl) {
		MyApplication.hostResUrl = hostResUrl;
	}

	public void setLight(boolean onOff) {
		try {
			// 获取服务灯IO状态
			// int result = cs.getGpioDeviceStatus(0x90);
			if (onOff == false && getCallStatus() == Constants.CALL_REQUEST) {
				// 服务灯电平拉低
				setCallStatus(Constants.CALL_CANCLE);
				if(enableServerLed){
					HardwareInterface.setCallGpioStatus(false);// 引脚致0
				}
				if(SharedPreferencesConfig.getAppMode(this).equals("hotel")){
					EventBus.getDefault().post(new UpdateBottomStateEvent());
				}
			} else if (onOff == true && getCallStatus() == Constants.CALL_CANCLE){
				// 服务灯电平拉高
				setCallStatus(Constants.CALL_REQUEST);
				if(enableServerLed){
					HardwareInterface.setCallGpioStatus(true);// 引脚致1
				}
				if(SharedPreferencesConfig.getAppMode(this).equals("hotel")){
					EventBus.getDefault().post(new UpdateBottomStateEvent());
				}
			} else if (onOff == true && getCallStatus() == Constants.CALL_REQUEST){
				//开机的时候，有时候会有这种状态
				setCallStatus(Constants.CALL_REQUEST);
				if(enableServerLed){
					HardwareInterface.setCallGpioStatus(true);// 引脚致1
				}
				if(SharedPreferencesConfig.getAppMode(this).equals("hotel")){
					EventBus.getDefault().post(new UpdateBottomStateEvent());
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			
		}
	}

	public void setLightHd(boolean onOff) {
		try {
			// 获取服务灯IO状态
			// int result = cs.getGpioDeviceStatus(0x90);
			if (onOff == false) {
				// 服务灯电平拉低
				HardwareInterface.setCallGpioStatus(false);// 引脚致0
			} else if (onOff == true){
				// 服务灯电平拉高
				HardwareInterface.setCallGpioStatus(true);// 引脚致1
			} else {
//				Log.i("call", "无效setLight:onOff="+onOff+",CallStatu="+getCallStatus()); 
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			
		}
	}
	public String changeLight() {
		String callMsg = "";
		if(NetworkUtil.isConnected(getBaseContext()) && MyApplication.isLogined()){
			EventBus.getDefault().post(new SyncCallEvent());
			try {
				if (getCallStatus() == Constants.CALL_REQUEST) {
					callMsg = SPAService.getCalling(getMAC(), Constants.CALL_CANCLE);
				} else {
					callMsg = SPAService.getCalling(getMAC(), Constants.CALL_REQUEST);
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
	
			}
			Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
			ModelBean d = gson.fromJson(callMsg, ModelBean.class);
			if (d != null && d.getMsg() != null) {
/*				呼叫不成功的状态
				{"code":-1,"msg":"mac、status或content参数格式非法！"}
				{"code":-2,"msg":"状态类型不存在！"}
				{"code":-3,"msg":"status不为数值！"}
				{"code":-4,"msg":"mac地址不存在！"}
				{"code":-5,"msg":"呼叫保存失败！"}
				{"code":-7,"msg":"[正在处理]该 + content + 已取消或已处理完成！"}
				{"code":-8,"msg":"[处理完成]没有处理中的 + content"}
				{"code":-9,"msg":"[取消请求]该 + content + 已取消或处理完成！"}
				{"code":-10,"msg":"呼叫操作失败！"}
				
				{"code":200,"msg":"成功！"}	
				{"code":-6,"msg":"[呼叫请求]有在进行中的 + content"}
*/
				//呼叫成功
				if (d.getCode().equals(200) || d.getCode().equals(-6)) {
					Log.i("call", "后台已有呼叫，更新本地状态,msg="+d.getMsg());
					setLight(true);
				} else {
					Log.i("call", "msg="+d.getMsg()); 
					setLight(false);
				}
	
	//			Log.i("jouson", "MyApp");
				EventBus.getDefault().post(new UpdateBottomStateEvent());
	
				return d.getMsg().toString();
			} else {
				return "线程出错";
			}
		}else{
			try {
				// 获取服务灯IO状态
				Log.i("MyApplication", "网络连接失败，直接控制服务灯。");
				// int result = cs.getGpioDeviceStatus(0x90);
				if (getCallStatus() == Constants.CALL_REQUEST) {
					// 服务灯电平拉低
					setLight(false);
				} else {
					// 服务灯电平拉高
					setLight(true);
				}
	
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				
			}
			
			return callMsg;
		}
	}

	public int getVersionName() throws Exception {
		// 获取packagemanager的实例
		PackageManager packageManager = getPackageManager();
		// getPackageName()是你当前类的包名，0代表是获取版本信息
		PackageInfo packInfo = packageManager.getPackageInfo(getPackageName(), 0);
		int version = packInfo.versionCode;
		return version;
	}

	public static void rebootSystem(Context context) {
		HardwareInterface.rebootSystem();
	}

	public static void rebootSystemDelay(int time) {

		try {
			Thread.sleep(time);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		rebootSystem(getContext());
	}

	/* 获取服务器的IP地址和端口号 */
	public static String getHostIpAndPort() {
		return SharedPreferencesConfig.getSpaServer(getContext());
	}

	/* 获取电视的位置号,如"大厅" */
	public static String getTvPosition() {
		return getDeviceInfo().getCategoryName();
	}

	/* 获取电视的名称,如"VIP7" */
	public static String getTvName() {
		return getDeviceInfo().getName();
	}

	public static String getApkVersion() {
		return apkVersion;
	}

	public static String getSystemVersion() {
		return systemVersion;
	}

	public void setSystemVersion(String systemVersion) {
		this.systemVersion = systemVersion;
	}

}
